<?php
defined('_JEXEC') or die('Restricted access');
$img_path = JURI::root(true).'/images/fileupload/';
?>
<div class='tab_content' id="tab_list_hopdong">
	<div class='container-fluid margin10'>
		<div class='row-fluid'>
			<div class='widget widget-padding span12'>
				<div class='widget-header'>
					<i class="icon-list-alt"></i>
					<h5>Danh sách hợp đồng</h5>
				</div>
				<div class='widget-body'>
					<div class='row-fluid'>
						<div class='span12'>
							<?php if(Utility::checkAccess("core.create", $this->canDo)): ?>
							<a class='btn btn-primary' href='#create_hopdong'>
								<i class='icon-plus icon-white'></i>
								<?php echo JText::_("COM_KETNOI_CREATEBTN") ?>
							</a>
							<?php endif; ?>
							<?php if(Utility::isAdmin()): ?>
							<a onclick="showModalPermission('hopdong')" class='btn btn-danger'>
								<i class='icon-lock icon-white'></i>
								Phân quyền
							</a>
							<?php endif; ?>
						</div>
					</div>
					
					<div class="row-fluid">
						<div class='span12'>
							<div id='grid_hopdong' class='margin10'></div>
						</div>
					</div>
					
				</div>
				
			</div>
		</div>
	</div>
</div>

<script>
    jQuery(document).ready(function(){    
        jQuery("#grid_hopdong").kendoGrid({
			dataSource: {
				transport: {
					read:{
						url:"index.php?option=com_ketnoi&view=hopdong&tmpl=raw",
						dataType:"json"
					}	
				},
				schema: {
					data:"results",
					total:"total"
				},
				pageSize: 10,
				serverPaging: true,
				batch: true
			},
			pageable:{
				pageSizes: true,
				messages: {
					display: "{0} - {1} <?php echo JText::_('COM_KETNOI_MESSAGEOF') ?> {2} <?php echo JText::_('COM_KETNOI_MESSAGEDATA') ?>",
					empty: "",
					page: "Page",
					of: "of {0}",
					itemsPerPage: "<?php echo JText::_('COM_KETNOI_MESSAGEITEMPERPAGE') ?>",
					first: "<?php echo JText::_('COM_KETNOI_GOTOFIRSTPAGE') ?>",
					previous: "<?php echo JText::_('COM_KETNOI_GOTOPREVIOUSPAGE') ?>",
					next: "<?php echo JText::_('COM_KETNOI_GOTONEXTPAGE') ?>",
					last: "<?php echo JText::_('COM_KETNOI_GOTOLASTPAGE') ?>",
					refresh: "Refresh"	
				}
			},
			scrollable:false,
			autoBind: false,
			detailTemplate: kendo.template($("#template").html()),
			detailInit: detailInit,
			columns: [
				{
					field:"ma_machine",
					title:"Mã máy"
				},
				{
					field:"ten_machine",
					title:"Tên máy",
					editable: false
				},
				{
					field:"serial",
					title:"Serial"
				},
				{
					field:"makhachhang",
					title:"Mã khách hàng"
				},
				{
					field:"tenkhachhang",
					title:"Tên khách hàng"
				},
				{
					field:"hinhthucmay",
					title:"Hình thức"
				},
				{
					field:"hopdongstatus",
					title:"Tình trạng"
				},
				{
					title:"",
					template:kendo.template($("#action_tpl").html()),
					width:100
				}
            ],
            dataBound:function(){
				if(this._data.length == 0)
				{
					var colspan = jQuery("#grid_hopdong").find('table thead tr th').length;
                    jQuery("#grid_hopdong").find('table tbody').append("<tr><td colspan='"+colspan+"'><?php echo JText::_('COM_KETNOI_EMPTYDATA') ?></td></tr>");
				}
				
				//make column on reponsive
				AddCellLabel("grid_hopdong");	
            }
		});
    })
    
    function detailInit(e) {
    	var detailRow = e.detailRow;

        	detailRow.find(".tabstrip").kendoTabStrip({
            	animation: {
            		sopen: { effects: "fadeIn" }
            	}
           });           
	}
</script>

<script type="text/x-kendo-template" id="action_tpl">
	<?php if(Utility::checkAccess("core.edit", $this->canDo)): ?>
  		<a onclick="edit_hash_hopdong(#= data.id #)" class="btn btn-info">
			<i class='icon-edit icon-large'></i>
			Sửa
		</a>
	<?php endif; ?>
</script>

<script type="text/x-kendo-template" id="template">
	<div class="tabstrip">
		<ul>
			<li class="k-state-active">
				Thông tin hợp đồng
            </li>
        </ul>
        <div>
       		<div class="row-fluid">
				<div class='span12'>
					<label class="control-label checkbox detailgrid">
				        	Mã nhà cung cấp:	
							<span class="detail_grid_info">#= manhacungcap #</span>  								
					</label>
				</div>
			</div>
			<div class="row-fluid">
				<div class='span12'>
					<label class="control-label checkbox detailgrid">
				        	Tên nhà cung cấp:	
							<span class="detail_grid_info">#= tennhacungcap #</span>  								
					</label>
				</div>
			</div>
				#if(data.hinhthuc == "maychothue"){#
			<div class="row-fluid">
					<div class='span12'>
						<label class="control-label checkbox detailgrid">
				        	Hợp đồng:	
							<span class="detail_grid_info">#= hopdong # tháng</span>  								
						</label>
					</div>
			</div>
			<div class="row-fluid">
					<div class='span12'>
						<label class="control-label checkbox detailgrid">
				        	Số trang mỗi tháng:	
							<span class="detail_grid_info">#= number_format(sotrang) #</span>  								
						</label>
					</div>
			</div>
			<div class="row-fluid">
					<div class='span12'>
						<label class="control-label checkbox detailgrid">
				        	Tiền vượt mức mỗi trang:	
							<span class="detail_grid_info">#= number_format(tienvuotmuc) #</span>  								
						</label>
					</div>
			</div>
			<div class="row-fluid">
					<div class='span12'>
						<label class="control-label checkbox detailgrid">
				        	Thuê bao:	
							<span class="detail_grid_info">#= number_format(thuebao) # tháng</span>  								
						</label>
					</div>
			</div>
				#}#
			</div>
        </div>
        
	</div>

</script>
